package com.qire.manhua.model.entity;

import com.qire.common.basic.StringUtil;
import com.qire.common.model.enumeration.VIPType;

/**
 * 漫画评论
 */
public class ComicComment {

    public final int    id;             //评论ID": 87,
    public final int    userId;         //用户ID": 19971,
    public final String userName;       //用户昵称: "清风未央",
    public final String userPortrait;   //用户头像:
    public final CharSequence content;        //评论内容": "很好看呀！继续努力！",
    public final String createTime;     //评论时间": "07-05 21:23",

    private int     replyCount;     //回复该评论数量": 4,
    private int     likeCount;          //点赞数: 54,
    private boolean isMyLike;           //我是否点赞: 0
    private VIPType vipType;            //vip类型

    public ComicComment(int id, int userId, String userName, String userPortrait, CharSequence content, String createTime,
                        int replyCount, int likeCount, boolean isMyLike, VIPType vipType) {
        this.id              = id;
        this.userId          = userId;
        this.userName        = userName;
        this.userPortrait    = userPortrait;
        this.content         = content;
        this.createTime      = createTime;
        this.replyCount      = replyCount;
        this.likeCount       = likeCount;
        this.isMyLike        = isMyLike;
        this.vipType         = vipType;
    }

    /**
     * 评论者是否是会员
     * @return true 是 false 不是
     */
    public boolean isVip() {
        return vipType != VIPType.NONE;
    }

    /**
     * 是否对该章节点过赞
     * @return true 是 false 否
     */
    public boolean isMyLike() {
        return isMyLike;
    }

    /**
     * 切换当前点赞状态
     */
    public void toggleLike() {
        isMyLike = !isMyLike;
        likeCount += isMyLike ? 1 : -1;
    }

    /** 点赞 */
    public void likeCountUp() {
        if(!isMyLike) {
            isMyLike = true;
            likeCount++;
        }
    }

    /** 取消点赞 */
    public void likeCountDown() {
        if(isMyLike) {
            isMyLike = false;
            likeCount--;
        }
    }

    /**
     * 点赞统计数
     * @return 点赞数量
     */
    public int likeCount() {
        return likeCount;
    }

    /**
     * 点赞统计数
     * @return 点赞数转String类型
     */
    public String likeCountToString() {
        return String.valueOf(likeCount);
    }

    public void addReply() {
        replyCount++;
    }

    /**
     * @return 评论被回复次数
     */
    public int replyCount() {
        return replyCount;
    }

    /**
     * @return 评论被恢复次数格式化转String
     */
    public String replyCountToString() {
        return StringUtil.toSymbol(replyCount);
    }

}
